//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.fuxi.cloud.desreport.a;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fuxi.cloud.common.vo.Result;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.fuxi.cloud.api.data.IDataSetFactory;
import com.fuxi.cloud.common.annotation.JimuLoginRequired;
import com.fuxi.cloud.common.util.CommonUtils;
import com.fuxi.cloud.common.util.JimuReportRepository;
import com.fuxi.cloud.common.util.MinioUtil;
import com.fuxi.cloud.common.util.OssBootUtil;
import com.fuxi.cloud.common.util.ViewFreemarker;
import com.fuxi.cloud.common.util.oConvertUtils;
import com.fuxi.cloud.common.vo.Result;
import com.fuxi.cloud.config.JmExposedConfig;
import com.fuxi.cloud.config.client.JmReportTokenClient;
import com.fuxi.cloud.desreport.b.c;
import com.fuxi.cloud.desreport.entity.JimuReport;
import com.fuxi.cloud.desreport.entity.JmReportDataSource;
import com.fuxi.cloud.desreport.entity.JmReportDb;
import com.fuxi.cloud.desreport.entity.JmReportDbParam;
import com.fuxi.cloud.desreport.model.QueryVO;
import com.fuxi.cloud.desreport.render.utils.FreeMarkerUtils;
import com.fuxi.cloud.desreport.service.IJimuReportService;
import com.fuxi.cloud.desreport.service.IJmReportDbFieldService;
import com.fuxi.cloud.desreport.service.IJmReportDbParamService;
import com.fuxi.cloud.desreport.service.IJmReportDbService;
import com.fuxi.cloud.desreport.service.IJmReportDbSourceService;
import com.fuxi.cloud.desreport.service.IJmReportExportExcel;
import com.fuxi.cloud.desreport.service.IJmReportMapService;
import com.fuxi.cloud.dyndb.vo.JmreportDynamicDataSourceVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.Base64Utils;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.HandlerMapping;

@RestController("designReportController")
@RequestMapping({"/jmreport"})
public class a {
    private static final Logger a = LoggerFactory.getLogger(a.class);
    @Value("${jeecg.path.upload:/opt/upload}")
    private String uploadpath;
    @Value("classpath:static/jmreport/json/excel.virtual.json")
    private Resource virtualJson;
    @Value("${jeecg.uploadType:local}")
    private String uploadType;
    @Value("${jeecg.jmreport.mode:dev}")
    private String reportMode;
    @Autowired
    private IJimuReportService jmReportDesignService;
    @Autowired
    private IJmReportDbService reportDbService;
    @Autowired
    private IJmReportDbParamService jmReportDbParamService;
    @Autowired
    private IJmReportDbFieldService jmReportDbFieldService;
    @Autowired
    private IJmReportDbSourceService jmReportDbSourceService;
    @Autowired
    private IJmReportMapService jmReportMapService;
    @Autowired
    private IJmReportExportExcel exportExcel;
    @Autowired
    private JmReportTokenClient jimuTokenClient;
    @Autowired
    private JmExposedConfig jmExposedConfig;

    public a() {
    }

    @RequestMapping({"/demo"})
    public void a(HttpServletRequest var1, HttpServletResponse var2) throws Exception {
        a.debug(" --- 进入报表设计器demo --- ");
        HashMap var3 = new HashMap();
        this.a((HttpServletRequest)var1, (HttpServletResponse)var2, (Map)var3, (String)"jmreport/desreport/demo.ftl");
    }

    @RequestMapping({"/list"})
    public void b(HttpServletRequest var1, HttpServletResponse var2) throws Exception {
        a.debug(" --- 进入报表设计器列表展示 --- ");
        HashMap var3 = new HashMap();
        this.a((HttpServletRequest)var1, (HttpServletResponse)var2, (Map)var3, (String)"jmreport/desreport/list.ftl");
    }

    @PostMapping({"/excelCreate"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestBody JimuReport var2) {
        a.debug("============EXCEL模板创建/编辑==========");

        try {
            String var3 = this.jimuTokenClient.getUsername(var1);
            var2.setCreateBy(var3);
            var2 = this.jmReportDesignService.excelCreate(var2);
        } catch (Exception var4) {
            a.error(var4.getMessage(), var4);
            return Result.error(var4.getMessage());
        }

        return Result.OK(var2);
    }

    @PostMapping({"/excelQueryName"})
    @JimuLoginRequired
    public Result<?> b(HttpServletRequest var1, @RequestBody JimuReport var2) {
        boolean var3 = this.jmReportDesignService.excelQueryName(var2);
        return var3 ? Result.OK() : Result.FAIL("您输入的报表名字已经存在，换一个吧！", var3);
    }

    @GetMapping({"/excelQuery"})
    @JimuLoginRequired
    public Result<?> a(@RequestParam(name = "reportType",required = false) String var1, @RequestParam(name = "name") String var2, @RequestParam(name = "pageNo",defaultValue = "1") Integer var3, @RequestParam(name = "pageSize",defaultValue = "10") Integer var4, HttpServletRequest var5) {
        a.debug("============EXCEL模板查询==========");
        return this.jmReportDesignService.excelQuery(var1, var2, var5, var3, var4);
    }

    @GetMapping({"/excelQueryByTemplate"})
    public Result<?> b(@RequestParam(name = "reportType",required = false) String var1, @RequestParam(name = "name") String var2, @RequestParam(name = "pageNo",defaultValue = "1") Integer var3, @RequestParam(name = "pageSize",defaultValue = "10") Integer var4, HttpServletRequest var5) {
        return this.jmReportDesignService.excelQueryByTemplate(var1, var2, var5, var3, var4);
    }

    @GetMapping({"/userinfo"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1) {
        Result var2 = Result.OK();
        String var3 = this.jimuTokenClient.getUsername(var1);
        var2.setMessage(var3);
        return Result.OK(var2);
    }

    public void c(HttpServletRequest var1, HttpServletResponse var2) throws Exception {
        a.debug(" --- 进入报表设计器 --- ");
        HashMap var3 = new HashMap();
        this.a((HttpServletRequest)var1, (HttpServletResponse)var2, (Map)var3, (String)"jmreport/desreport/index.ftl");
    }

    @RequestMapping({"/index/{id}"})
    public void a(@PathVariable("id") String var1, HttpServletRequest var2, HttpServletResponse var3) throws Exception {
        a.debug(" --- 进入报表设计器 --- ");
        HashMap var4 = new HashMap();
        if (oConvertUtils.isNotEmpty(var1)) {
            var4.put("id", var1);
        }

        var4.put("mode", this.reportMode);
        this.a((HttpServletRequest)var2, (HttpServletResponse)var3, (Map)var4, (String)"jmreport/desreport/index.ftl");
    }

    @RequestMapping({"/view/{id}"})
    public void b(@PathVariable("id") String var1, HttpServletRequest var2, HttpServletResponse var3) throws Exception {
        HashMap var4 = new HashMap();
        if (oConvertUtils.isNotEmpty(var1)) {
            var4.put("id", var1);
        }

        var4.put("shareView", "0");
        this.a((HttpServletRequest)var2, (HttpServletResponse)var3, (Map)var4, (String)"jmreport/desreport/view.ftl");
    }

    @RequestMapping({"/shareView/{id}"})
    public void a(@PathVariable("id") String var1, HttpServletResponse var2, HttpServletRequest var3) throws Exception {
        HashMap var4 = new HashMap();
        if (oConvertUtils.isNotEmpty(var1)) {
            var4.put("id", var1);
        }

        var4.put("shareView", "1");
        this.a((HttpServletRequest)var3, (HttpServletResponse)var2, (Map)var4, (String)"jmreport/desreport/view.ftl");
    }

    @PostMapping({"/addViewCount/{id}"})
    public Result<?> a(@PathVariable("id") String var1) {
        JimuReport var2 = this.jmReportDesignService.getById(var1);
        if (var2 == null) {
            return Result.error("未找到具体报表信息");
        } else {
            Long var3 = var2.getViewCount();
            if (var3 == null) {
                var3 = 0L;
            }

            var3 = var3 + 1L;
            a.debug("新增浏览次数：" + var3 + ",>>" + var1);
            var2.setViewCount(var3);
            Integer var4 = this.jmReportDesignService.updateById(var2);
            boolean var5 = false;
            if (var4 > 0) {
                var5 = true;
            }

            return Result.OK("", var5);
        }
    }

    @GetMapping({"/checkParam/{id}"})
    public Result<List<JmReportDbParam>> b(@PathVariable(name = "id") String var1) {
        Result var2 = new Result();
        List var3 = this.jmReportDesignService.queryReportParam(var1);
        if (var3 != null && var3.size() != 0) {
            var2.setSuccess(true);
            var2.setResult(var3);
        } else {
            var2.setSuccess(false);
        }

        return var2;
    }

    @RequestMapping({"/show"})
    public Result<?> a(@RequestParam(name = "id") String var1, HttpServletRequest var2) {
        String var3 = var2.getParameter("params");
        String var4 = this.jimuTokenClient.getUsername(var2);
        if (!JimuReportRepository.getSaas()) {
            var4 = "";
        }

        try {
            return this.jmReportDesignService.show(var1, var3, var4);
        } catch (Exception var6) {
            a.error(var6.getMessage(), var6);
            return Result.error(var6.getMessage());
        }
    }

    @PostMapping({"/save"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestBody JSONObject var2) {
        try {
            JimuReport var3 = this.jmReportDesignService.saveReport(var2, var1);
            return Result.OK(var3);
        } catch (Exception var4) {
            a.error(var4.getMessage(), var4);
            return Result.error("保存失败！");
        }
    }

    @GetMapping({"/get/{id}"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @PathVariable("id") String var2) {
        a.debug("============EXCEL JSON数据查询==========");
        JimuReport var3 = this.jmReportDesignService.getById(var2);
        return Result.OK(var3);
    }

    @GetMapping({"/mockPieData"})
    public Result<?> a() {
        a.debug("============模拟图表数据==========");
        ArrayList var1 = new ArrayList();
        String[] var2 = new String[]{"IE", "Safari", "Firefox", "Opera", "Chrome"};
        Random var3 = new Random();
        String[] var4 = var2;
        int var5 = var2.length;

        for(int var6 = 0; var6 < var5; ++var6) {
            String var7 = var4[var6];
            HashMap var8 = new HashMap();
            var8.put("name", var7);
            var8.put("value", var3.nextInt(1901) + 100);
            var1.add(var8);
        }

        return Result.OK(var1);
    }

    @GetMapping({"/mockChartData"})
    public Result<?> b() {
        a.debug("============模拟图表数据2==========");
        ArrayList var1 = new ArrayList();
        String[] var2 = new String[]{"邮件营销", "联盟广告", "视频广告", "直接访问", "搜索引擎"};
        Random var3 = new Random();
        String[] var4 = var2;
        int var5 = var2.length;

        for(int var6 = 0; var6 < var5; ++var6) {
            String var7 = var4[var6];
            HashMap var8 = new HashMap();
            var8.put("name", var7);
            ArrayList var9 = new ArrayList();

            for(int var10 = 0; var10 < 7; ++var10) {
                var9.add(var3.nextInt(1901) + 100);
            }

            var8.put("data", var9);
            var1.add(var8);
        }

        return Result.OK(var1);
    }

    @PostMapping({"/upload"})
    public Result<?> d(HttpServletRequest var1, HttpServletResponse var2) {
        Result var3 = new Result();

        try {
            MultipartHttpServletRequest var4 = (MultipartHttpServletRequest)var1;
            MultipartFile var5 = var4.getFile("file");
            String var6 = var1.getParameter("bizType");
            if (oConvertUtils.isEmpty(var6)) {
                var6 = this.uploadType;
            }

            String var7 = "";
            a.debug("文件上传开始------------------------------uploadType  " + var6);
            if ("alioss".equals(var6)) {
                a.debug("进入OSS方法----->CommonConstant.UPLOAD_TYPE_OSS  alioss");
                var7 = OssBootUtil.upload(var5, "designreport/images");
            } else if ("minio".equals(var6)) {
                a.debug("进入MINIO方法----->CommonConstant.UPLOAD_TYPE_MINIO  minio");
                var7 = MinioUtil.upload(var5, "designreport/images");
            } else if ("local".equals(var6)) {
                a.debug("进入LOCAL方法----->CommonConstant.UPLOAD_TYPE_LOCAL local");
                var7 = this.a(var5, "excel_online");
            }

            a.debug("文件上传结束------------------------------返回url", var7);
            var3.setMessage(var7);
            var3.setSuccess(true);
        } catch (Exception var8) {
            var3.setSuccess(false);
            var3.setMessage("");
            a.error(var8.getMessage(), var8);
        }

        return var3;
    }

    @CrossOrigin
    @GetMapping({"/img/**"})
    public void e(HttpServletRequest var1, HttpServletResponse var2) {
        String var3 = d(var1);
        BufferedInputStream var4 = null;
        ServletOutputStream var5 = null;

        try {
            var3 = var3.replace("..", "");
            if (var3.endsWith(",")) {
                var3 = var3.substring(0, var3.length() - 1);
            }

            var2.setContentType("image/jpeg;charset=utf-8");
            String var6 = this.uploadpath;
            String var7 = var6 + File.separator + var3;
            var4 = new BufferedInputStream(new FileInputStream(var7));
            var5 = var2.getOutputStream();
            byte[] var8 = new byte[1024];

            int var9;
            while((var9 = var4.read(var8)) > 0) {
                var5.write(var8, 0, var9);
            }

            var2.flushBuffer();
        } catch (IOException var22) {
            a.error("预览图片失败" + var22.getMessage(), var22);
        } finally {
            if (var4 != null) {
                try {
                    var4.close();
                } catch (IOException var21) {
                    a.error(var21.getMessage(), var21);
                }
            }

            if (var5 != null) {
                try {
                    var5.close();
                } catch (IOException var20) {
                    a.error(var20.getMessage(), var20);
                }
            }

        }

    }

    private String a(File var1) {
        Scanner var2 = null;
        StringBuilder var3 = new StringBuilder();

        try {
            var2 = new Scanner(var1, "utf-8");

            while(var2.hasNextLine()) {
                var3.append(var2.nextLine());
            }
        } catch (Exception var8) {
            var8.printStackTrace();
        } finally {
            if (var2 != null) {
                var2.close();
            }

        }

        return var3.toString();
    }

    private void a(HttpServletRequest var1, HttpServletResponse var2, Map var3, String var4) throws Exception {
        try {
            var3.put("base", var1.getContextPath());
            var3.put("baseURL", c.a(var1));
            var3.put("customPrePath", oConvertUtils.getString(var1.getParameter("customPrePath"), ""));
            var3.put("reportConfig", JSON.toJSONString(this.jmExposedConfig));
        } catch (Exception var6) {
            var6.printStackTrace();
            var3.put("message", var6.getMessage());
        }

        ViewFreemarker.view(var1, var2, var4, var3);
    }

    private static String d(HttpServletRequest var0) {
        String var1 = (String)var0.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
        String var2 = (String)var0.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
        return (new AntPathMatcher()).extractPathWithinPattern(var2, var1);
    }

    @PostMapping({"/loadTable"})
    public Result<?> b(HttpServletRequest var1, @RequestParam("dbSource") String var2) {
        a.debug("============加载表信息loadTable()==========");
        if (ObjectUtil.isNotEmpty(var2)) {
            JmreportDynamicDataSourceVo var3 = this.jmReportDbSourceService.getByDbKey(var2);
            if (var3 == null) {
                return Result.error("数据源不存在");
            }
        }

        List var4 = this.reportDbService.loadDataSourceTable(var2);
        return Result.OK(var4);
    }

    @PostMapping({"/loadTableData"})
    public Result<?> a(HttpServletRequest var1, @RequestParam(value = "dbSource",required = false) String var2, @RequestParam(value = "tableName",required = false) String var3, @RequestParam(value = "pageNo",required = false) Integer var4, @RequestParam(value = "pageSize",required = false) Integer var5, @RequestParam(value = "sql",required = false) String var6) {
        a.debug("============加载表数据信息loadTableData()==========");
        if (ObjectUtil.isNotEmpty(var2)) {
            JmreportDynamicDataSourceVo var7 = this.jmReportDbSourceService.getByDbKey(var2);
            if (var7 == null) {
                return Result.error("数据源不存在");
            }
        }

        Map var8 = this.reportDbService.loadTableData(var2, var3, var4, var5, var6);
        return Result.OK(var8);
    }

    @PostMapping({"/queryFieldBySql"})
    public Result<?> a(@RequestBody JSONObject var1) {
        a.debug("============解析sql==========");
        String var2 = var1.getString("sql");
        String var3 = var1.getString("dbSource");
        if (ObjectUtil.isNotEmpty(var3)) {
            JmreportDynamicDataSourceVo var4 = this.jmReportDbSourceService.getByDbKey(var3);
            if (var4 == null) {
                return Result.error("数据源不存在");
            }
        }

        try {
            Map var6 = this.reportDbService.parseReportSql(var2, var3);
            return Result.OK("解析成功", var6);
        } catch (Exception var5) {
            return Result.error(var5.getMessage());
        }
    }

    @PostMapping({"/queryFieldByBean"})
    public Result<?> b(@RequestBody JSONObject var1) {
        a.debug("============解析javabean==========");
        String var2 = var1.getString("javaType");
        String var3 = var1.getString("javaValue");
        Boolean var4 = var1.getBoolean("isPage");
        JSONObject var5 = var1.getJSONObject("param");
        Map var6 = c.a(var5);

        try {
            Object var7 = c.c(var2, var3);
            if (var7 != null && var7 instanceof IDataSetFactory) {
                IDataSetFactory var8 = (IDataSetFactory)var7;
                List var9 = c.a(var8, var6, var4);
                return var9 != null && var9.size() != 0 ? Result.OK("解析成功", var9) : Result.error("解析成功但是无数据!");
            } else {
                return Result.error("javabean数据集需要实现接口IDataSetFactory");
            }
        } catch (Exception var10) {
            return Result.error(var10.getMessage());
        }
    }

    @PostMapping({"/executeSelectApi"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestParam("api") String var2, @RequestParam("method") String var3) {
        String var4 = var1.getParameter("token");
        if (ObjectUtil.isEmpty(var4)) {
            var4 = var1.getHeader("token");
        }

        a.info("报表executeSelectApi:: api= " + var2 + ", method= " + var3 + ", token= " + var4);
        Map var5 = this.reportDbService.executeSelectApi(var2, var3, var4);
        List var6 = this.reportDbService.parseData(var5);
        return Result.OK(var6);
    }

    @PostMapping({"/saveDb"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestBody JmReportDb var2) {
        a.debug("============saveDb==========");

        try {
            String var3 = this.jimuTokenClient.getUsername(var1);
            var2.setCreateBy(var3);
            Date var4 = new Date();
            var2.setCreateTime(var4);
            var2.setUpdateTime(var4);
            var2 = this.reportDbService.saveDb(var2);
        } catch (Exception var5) {
            a.error(var5.getMessage(), var5);
            return Result.error(var5.getMessage());
        }

        return Result.OK(var2);
    }

    @GetMapping({"/field/tree/{reportId}"})
    @JimuLoginRequired
    public Result<?> c(HttpServletRequest var1, @PathVariable("reportId") String var2) {
        a.debug("============fieldTree==========");
        Object var3 = new ArrayList();

        try {
            var3 = this.reportDbService.fieldTree(var2);
        } catch (Exception var5) {
            var5.printStackTrace();
        }

        return Result.OK(var3);
    }

    @GetMapping({"/queryIsPage/{reportId}"})
    @JimuLoginRequired
    public Result<?> d(HttpServletRequest var1, @PathVariable("reportId") String var2) {
        boolean var3 = this.reportDbService.queryIsPage(var2);
        return Result.OK(var3);
    }

    @GetMapping({"loadDbData/{dbId}"})
    @JimuLoginRequired
    public Result<?> e(HttpServletRequest var1, @PathVariable("dbId") String var2) {
        a.debug("============loadDbData==========");
        Map var3 = this.reportDbService.loadDbData(var2);
        return Result.OK(var3);
    }

    @GetMapping({"initDataSource"})
    @JimuLoginRequired
    public Result<?> b(HttpServletRequest var1) {
        String var2 = this.jimuTokenClient.getUsername(var1);
        a.debug("============initDataSource==========");
        List var3 = this.reportDbService.initDataSource(var2);
        return Result.OK(var3);
    }

    @GetMapping({"/delDbData/{dbId}"})
    @JimuLoginRequired
    public Result<?> f(HttpServletRequest var1, @PathVariable("dbId") String var2) {
        a.debug("============delDbData==========");
        this.reportDbService.delDbData(var2);
        return Result.OK();
    }

    @PostMapping({"/deleteParamByIds"})
    @JimuLoginRequired
    public Result<?> b(HttpServletRequest var1, @RequestBody JSONObject var2) {
        a.debug("============deleteParamByIds==========");
        JSONArray var3 = var2.getJSONArray("selectIds");
        String var4 = var2.getString("id");
        String var5 = var2.getString("dbDynSql");
        this.jmReportDbParamService.deleteParamByIdsAndUpdateDbSql(var3, var4, var5);
        return Result.OK();
    }

    @DeleteMapping({"/deleteFieldByIds"})
    @JimuLoginRequired
    public Result<?> g(HttpServletRequest var1, @RequestBody String var2) {
        a.debug("============deleParams==========");
        this.jmReportDbFieldService.deleteByIds(var2);
        return Result.OK();
    }

    @DeleteMapping({"/delete"})
    @ResponseBody
    @JimuLoginRequired
    public Result<?> h(HttpServletRequest var1, @RequestParam(name = "id",required = true) String var2) {
        JimuReport var3 = new JimuReport();
        var3.setId(var2);
        var3.setDelFlag(1);
        this.jmReportDesignService.updateById(var3);
        return Result.OK("删除成功!", true);
    }

    @GetMapping({"/reportCopy"})
    @ResponseBody
    @JimuLoginRequired
    public Result<?> i(HttpServletRequest var1, @RequestParam(name = "id",required = true) String var2) {
        try {
            String var3 = this.jimuTokenClient.getUsername(var1);
            JimuReport var4 = new JimuReport();
            var4.setCreateBy(var3);
            Date var5 = new Date();
            var4.setCreateTime(var5);
            var4.setUpdateTime(var5);
            var4.setId(var2);
            this.jmReportDesignService.reportCopy(var4);
        } catch (Exception var6) {
            var6.printStackTrace();
            return Result.error(403, "您没有权限");
        }

        return Result.OK("复制成功!", true);
    }

    @GetMapping({"/setTemplate"})
    @ResponseBody
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestParam(name = "id",required = true) String var2, @RequestParam(name = "template",required = true) Integer var3) {
        JimuReport var4 = new JimuReport();
        var4.setId(var2);
        var4.setTemplate(var3);
        Integer var5 = this.jmReportDesignService.updateById(var4);
        boolean var6 = false;
        if (var5 > 0) {
            var6 = true;
        }

        return Result.OK("设置成功!", var6);
    }

    @PostMapping({"/importExcel"})
    @ResponseBody
    @JimuLoginRequired
    public Result<Object> a(HttpServletRequest var1, @RequestParam("file") MultipartFile var2) throws IOException {
        Result var3 = new Result();
        Map var4 = this.jmReportDesignService.importExcel(var2);
        if (var4.size() > 0 && !var4.isEmpty()) {
            var3.setResult(var4);
            var3.setSuccess(true);
        } else {
            var3.setSuccess(false);
        }

        return var3;
    }

    @PostMapping({"/exportAllExcel"})
    @ResponseBody
    public Result<Object> a(HttpServletRequest var1, HttpServletResponse var2, @RequestBody JSONObject var3) throws IOException {
        HashMap var4 = new HashMap(var1.getParameterMap());
        boolean var5 = var4.containsKey("token");
        String var6 = "";
        if (JimuReportRepository.getSaas()) {
            var6 = this.jimuTokenClient.getUsername(var1);
        }

        if (var5) {
            var4.remove("token");
        }

        String var7 = var3.getString("excelConfigId");
        JSONObject var8 = var3.getJSONObject("queryParam");
        var8.put("printAll", true);
        JSONArray var9 = var3.getJSONArray("base64Arry");
        Result var10 = this.jmReportDesignService.show(var7, var8.toJSONString(), var6);
        JimuReport var11 = (JimuReport)var10.getResult();
        Map var12 = this.exportExcel.exportExcel(var11, var4, var9);
        File var13 = new File(var12.get("name").toString());
        var2.setContentType("application/force-download");
        var2.setHeader("Content-Disposition", "attachment; fileName=" + var13.getName() + ";filename*=utf-8''" + URLEncoder.encode(var13.getName(), "UTF-8"));
        ServletOutputStream var14 = var2.getOutputStream();
        XSSFWorkbook var15 = (XSSFWorkbook)var12.get("workbook");
        ByteArrayOutputStream var16 = new ByteArrayOutputStream();
        HashMap var17 = new HashMap();

        try {
            var15.write(var16);
            String var18 = Base64Utils.encodeToString(var16.toByteArray());
            var17.put("file", var18);
            var17.put("success", true);
            var17.put("name", var13.getName());
        } catch (IOException var27) {
            var27.printStackTrace();
            var17.put("error", var27.getMessage());
        } finally {
            try {
                var16.close();
            } catch (IOException var26) {
                var26.printStackTrace();
            }

        }

        return Result.OK(var17);
    }

    @RequestMapping({"/print"})
    public void a(HttpServletResponse var1, HttpServletRequest var2) throws Exception {
        HashMap var3 = new HashMap();
        this.a((HttpServletRequest)var2, (HttpServletResponse)var1, (Map)var3, (String)"jmreport/desreport/print.ftl");
    }

    @PostMapping({"/putFile"})
    @ResponseBody
    @JimuLoginRequired
    public Result<?> j(HttpServletRequest var1, @RequestParam String var2) {
        Result var3 = new Result();

        try {
            MultipartHttpServletRequest var4 = (MultipartHttpServletRequest)var1;
            MultipartFile var5 = var4.getFile("file");
            String var6 = "";
            if ("alioss".equals(this.uploadType)) {
                var6 = OssBootUtil.upload(var5, "designreport/images");
            } else if ("minio".equals(this.uploadType)) {
                var6 = MinioUtil.upload(var5, "designreport/images");
            }

            JimuReport var7 = new JimuReport();
            if (ObjectUtil.isNotEmpty(var6) && ObjectUtil.isNotEmpty(var2)) {
                var7.setId(var2);
                var7.setThumb(var6);
                this.jmReportDesignService.updateById(var7);
                var3.setMessage("封面图上传成功!");
            }
        } catch (Exception var8) {
            var3.setSuccess(false);
            var3.setMessage("");
            a.error(var8.getMessage(), var8);
        }

        return var3;
    }

    @GetMapping({"/download/image"})
    @ResponseBody
    public Result<Object> f(HttpServletRequest var1, HttpServletResponse var2) throws IOException {
        String var3 = var1.getParameter("imageUrl");
        Result var4 = new Result();
        if (ObjectUtil.isEmpty(var3)) {
            var4.setSuccess(false);
            return var4;
        } else {
            if (!var3.contains("http")) {
                var4.setSuccess(true);
                var4.setResult(var3);
            }

            String var5 = File.separator + "designreport" + File.separator + "images" + File.separator;
            String var6 = var3.substring(var3.lastIndexOf("/") + 1);
            File var7 = new File(this.uploadpath + var5);
            if (!var7.exists()) {
                var7.mkdirs();
            }

            a.debug("----imageUrl------" + var3);
            a.debug("----fileName------" + var6);
            a.debug("----downFilePath------" + this.uploadpath + var5 + var6);
            File var8 = new File(this.uploadpath + var5 + var6);
            if (!var8.exists()) {
                c.a(var3, var8);
            }

            var4.setSuccess(true);
            var4.setResult(var5 + var6);
            return var4;
        }
    }

    private String a(MultipartFile var1, String var2) {
        try {
            String var3 = this.uploadpath;
            a.info(" --- local upload path : " + var3 + " --- ");
            String var4 = null;
            File var5 = new File(var3 + File.separator + var2 + File.separator);
            if (!var5.exists()) {
                var5.mkdirs();
            }

            String var6 = var1.getOriginalFilename();
            var6 = CommonUtils.getFileName(var6);
            if (var6.indexOf(".") != -1) {
                var4 = var6.substring(0, var6.lastIndexOf(".")) + "_" + System.currentTimeMillis() + var6.substring(var6.indexOf("."));
            } else {
                var4 = var6 + "_" + System.currentTimeMillis();
            }

            String var7 = var5.getPath() + File.separator + var4;
            File var8 = new File(var7);
            FileCopyUtils.copy(var1.getBytes(), var8);
            String var9 = null;
            if (oConvertUtils.isNotEmpty(var2)) {
                var9 = var2 + File.separator + var4;
            } else {
                var9 = var4;
            }

            if (var9.contains("\\")) {
                var9 = var9.replace("\\", "/");
            }

            return var9;
        } catch (IOException var10) {
            a.error(var10.getMessage(), var10);
            return "";
        }
    }

    @PostMapping({"/addDataSource"})
    @JimuLoginRequired
    public Result<?> a(HttpServletRequest var1, @RequestBody JmReportDataSource var2) {
        return this.reportDbService.addDataSource(var2, var1);
    }

    @PostMapping({"/querySourceCode"})
    @JimuLoginRequired
    public Result<?> b(HttpServletRequest var1, @RequestBody JmReportDataSource var2) {
        boolean var3 = this.reportDbService.querySourceCode(var2);
        return Result.OK(var3);
    }

    @PostMapping({"/delDataSource"})
    @JimuLoginRequired
    public Result<?> c(HttpServletRequest var1, @RequestBody JmReportDataSource var2) {
        this.reportDbService.delDataSource(var2);
        return Result.OK("删除成功", true);
    }

    @PostMapping({"/testConnection"})
    public Result a(@RequestBody JmreportDynamicDataSourceVo var1) {
        Connection var2 = null;

        Result var4;
        try {
            Class.forName(var1.getDbDriver());
            var2 = DriverManager.getConnection(var1.getDbUrl(), var1.getDbUsername(), var1.getDbPassword());
            Result var3;
            if (var2 != null) {
                var3 = Result.OK("数据库连接成功", true);
                return var3;
            }

            var3 = Result.OK("数据库连接失败：错误未知", true);
            return var3;
        } catch (ClassNotFoundException var17) {
            a.error(var17.toString());
            var4 = Result.error("数据库连接失败：驱动类不存在");
        } catch (Exception var18) {
            a.error(var18.toString());
            var4 = Result.error("数据库连接失败：" + var18.getMessage());
            return var4;
        } finally {
            try {
                if (var2 != null && !var2.isClosed()) {
                    var2.close();
                }
            } catch (SQLException var16) {
                a.error(var16.toString());
            }

        }

        return var4;
    }

    @RequestMapping({"/qurestApi"})
    public Result<?> b(@RequestParam(name = "apiSelectId") String var1, HttpServletRequest var2) {
        String var3 = "";
        JmReportDb var4 = this.reportDbService.getById(var1);
        String var5 = var2.getParameter("token");
        if (ObjectUtil.isEmpty(var5)) {
            var5 = var2.getHeader("token");
        }

        String var6 = var4.getApiUrl();
        List var7 = this.jmReportDbParamService.list(var4.getId());
        HashMap var8 = new HashMap();
        Iterator var9 = var7.iterator();

        while(var9.hasNext()) {
            JmReportDbParam var10 = (JmReportDbParam)var9.next();
            if (var6.indexOf(var10.getParamName()) > 0) {
                var8.put(var10.getParamName(), var10.getParamValue());
            }
        }

        String var12 = FreeMarkerUtils.a(var6, var8);
        var12 = var12.replace("'", "");
        if ("0".equals(var4.getApiMethod())) {
            var3 = c.b(var12, var5);
        } else {
            var3 = c.a(var12, var5, (JSONObject)null);
        }

        JSONObject var11 = JSONObject.parseObject(var3);
        return Result.OK(var11);
    }

    @RequestMapping({"/qurestSql"})
    public Result<?> c(@RequestParam(name = "apiSelectId") String var1, HttpServletRequest var2) {
        String var3 = this.jimuTokenClient.getUsername(var2);
        if (!JimuReportRepository.getSaas()) {
            var3 = "";
        }

        JmReportDb var4 = this.reportDbService.getById(var1);
        List var5 = this.reportDbService.qurestechSql(var4);
        this.jmReportDesignService.replaceDbCode(var1, var3, var5);
        return Result.OK(c.b(var5));
    }

    @GetMapping({"/dataCodeExist"})
    public Result<Boolean> a(@RequestParam(name = "reportId") String var1, @RequestParam(name = "code") String var2) {
        int var3 = this.reportDbService.getCount(var1, var2);
        return Result.OK(var3 > 0);
    }

    @GetMapping({"/getQueryInfo"})
    public Result<List<QueryVO>> d(@RequestParam(name = "reportId") String var1, HttpServletRequest var2) {
        String var3 = this.jimuTokenClient.getUsername(var2);
        if (!JimuReportRepository.getSaas()) {
            var3 = "";
        }

        List var4 = this.jmReportDesignService.getReportQueryInfo(var1, var3);
        return Result.OK(var4);
    }

    @RequestMapping({"/addChart"})
    @JimuLoginRequired
    public Result<?> e(@RequestParam(name = "chartType") String var1, HttpServletRequest var2) {
        JSONObject var3 = this.jmReportDesignService.addChart(var1);
        return Result.OK(var3);
    }

    @PostMapping({"/queryTableName"})
    public Result<?> b(HttpServletRequest var1, @RequestParam("dbSource") String var2, @RequestParam("tableName") String var3) {
        List var4 = this.reportDbService.queryTableName(var2, var3);
        return Result.OK(var4);
    }

    @GetMapping({"/getReportByUser"})
    public Result<List<JimuReport>> k(HttpServletRequest var1, @RequestParam(name = "reportId") String var2) {
        Result var3 = new Result();
        String var4 = this.jimuTokenClient.getUsername(var1);
        List var5 = this.jmReportDesignService.getReportByUser(var4, var2);
        var3.setSuccess(true);
        var3.setResult(var5);
        return var3;
    }

    @GetMapping({"/getReportChars"})
    public Result<List<JSONObject>> b(@RequestParam(name = "reportId") String var1, @RequestParam(name = "charId",required = false) String var2) {
        ArrayList var3 = new ArrayList();
        JimuReport var4 = this.jmReportDesignService.getById(var1);
        if (var4 != null) {
            String var5 = var4.getJsonStr();
            JSONObject var6 = JSONObject.parseObject(var5);
            Object var7 = var6.get("chartList");
            if (null != var7) {
                JSONArray var8 = JSONArray.parseArray(var7.toString());

                for(int var9 = 0; var9 < var8.size(); ++var9) {
                    JSONObject var10 = new JSONObject();
                    Object var11 = var8.getJSONObject(var9).get("layer_id");
                    Object var12 = var8.getJSONObject(var9).get("config");
                    JSONObject var13 = JSONObject.parseObject(var12.toString());
                    JSONObject var14 = var13.getJSONObject("title");
                    Object var15 = var14.get("text");
                    if (null != var15 && null != var11) {
                        if (oConvertUtils.isNotEmpty(var2) && !var2.equals(var11)) {
                            var10.put("id", var11);
                            var10.put("name", var15);
                            var3.add(var10);
                        }

                        if (oConvertUtils.isEmpty(var2)) {
                            var10.put("id", var11);
                            var10.put("name", var15);
                            var3.add(var10);
                        }
                    }
                }
            }
        }

        return Result.OK(var3);
    }

    @GetMapping({"/getCharData"})
    public Result<JSONObject> a(@RequestParam(name = "reportId") String var1, @RequestParam(name = "charId") String var2, @RequestParam(name = "params") String var3, HttpServletRequest var4) {
        String var5 = var4.getParameter("X-Access-Token");
        JSONObject var6 = this.jmReportDesignService.getCharData(var1, var2, var3, var5);
        return Result.OK(var6);
    }

    @GetMapping({"/verificationToken"})
    public void c(HttpServletRequest var1) {
        this.jimuTokenClient.verifyToken(var1);
    }
}
